/*
 * @lc app=leetcode.cn id=1185 lang=javascript
 *
 * [1185] 一周中的第几天
 */

// @lc code=start
/**
 * @param {number} day
 * @param {number} month
 * @param {number} year
 * @return {string}
 */
var dayOfTheWeek = function(day, month, year) { 
    const ms = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
    const ds = ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"]
    const op = (y) => y % 400 === 0 || (y % 4 === 0 && y % 100 !== 0)
    let s = day, i = 1971
    while(i < year) s += op(i++) ? 366 : 365
    while(--month) s += ms[month - 1] + ((month === 2 && op(year)) ? 1 : 0)
    return ds[(4 + s) % 7]

};
// @lc code=end

